/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = ora_STRING.c                                       */
/*  NOTE      =                                                    */
/*  DATE      = 2014/11/12 by songbb                               */
/*******************************************************************/

#include <stdio.h>
#include <memory.h>
#include <string.h>
#include <stdlib.h>
#include <netinet/in.h>

#include "frcomm.h"
#include "frstr.h"
#include "frmem.h"
#include "frlog.h"

#include "../../ora_core.h"
#include "../../comm/ora_comm.h"
#include "../../comm/ora_util.h"

/*******************************************************************************
*  FUNC     :  解析字符串类型
*  ARGS     :  *p_payload                           (数据内容)
*           :  ui_payload_len                       (数据长度)
*           :  **pp_out                             (解析后的字符串内容)
*           :  *p_i_out_len                         (解析后的字符串长度)
*  RTN      :  0                                    (FR_SUCC)
*              1                                    (FR_FAIL)
*  NOTE     :
*******************************************************************************/
int ora_STRING_toChar(char *p_payload
                    , unsigned int ui_payload_len
                    , char **pp_out
                    , int *p_i_out_len)
{
    char *p_out = NULL;

    // TODO: 暂未考虑字符编码
    if ((p_out = (char *) frmalloc((ui_payload_len + 1) * sizeof(char))) == NULL)
    {
        ORA_PRINT_EMERG("can not malloc memory\n");
        ORA_FRLOG_ERROR("can not malloc memory");
        return FR_FAIL;
    }
    memcpy(p_out, p_payload, ui_payload_len);
    p_out[ui_payload_len] = '\0';

    *pp_out = p_out;
    *p_i_out_len = ui_payload_len;

    return FR_SUCC;
}
